<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件插槽</title>
</head>

<body>
    <script src="/js/vue.js"></script>
    <div id="app">
        <p>{{msg}}</p>
        <cpn>
            <template v-slot:right>
                <button>button</button>
            </template>
        </cpn>
        <cpn>
            <template v-slot:left="slotProps">
                <span>{{slotProps.btn}}</span>
            </template>
        </cpn>
        <cpn>
            <i>hhhhhh</i>
        </cpn>

    </div>

    <template id="cpnT">
        <div>
            <h2>子组件内容</h2>
            <!-- 普通的插槽 -->
            <slot></slot>

            <!-- 拥有默认内容的插槽 -->
            <slot><button>click</button></slot> <!-- 有默认的内容 -->
            
            <!-- 具名插槽 -->
            <slot name="right"></slot>

            <!-- 作用域插槽 -->
            <slot name="left" v-bind:btn="btnName"></slot>

        </div>
    </template>


    <script>
        //子组件
        const cpn = {
            template: `#cpnT`,
            methods: {
                showMessage() {
                    console.log("message");
                }
            },
            data() {
                return {
                    btnName: "span1111"
                }
            }
        }

        //父组件
        let app = new Vue({
            el: "#app",
            data: {
                msg: 'hello world'
            },
            components: {
                cpn
            }
        })
    </script>
</body>

</html>